<template>
    <div class="com-merchant-select">
        <select-group :select-list="merchant"
                      class="c-condition-item"
                      ref="merchant"
                      text-key="nickName"
                      @select="accountList=[accountList[0]].concat($event.weChatPublics)"
                      label="商户："
                      placeholder="请选择"></select-group>
        <select-group :select-list="accountList"
                      class="c-condition-item"
                      ref="accountList"
                      text-key="nickName"
                      label="公众号："
                      placeholder="请选择"></select-group>
    </div>
</template>

<script>
    import axios from 'axios';
    import SelectGroup from '@/component/selectGroup.vue';
    export default {
        data(){
            return {
                merchant: [
                    {nickName: '全部', id: null, weChatPublics: [], selected: true},
                ],
                accountList: [
                    {nickName: '全部', appid: null, selected: true},
                ],
            }
        },
        created(){
            this.getAccounts();
        },
        methods: {
            // 获取商户数据
            getAccounts(){
                axios({
                    method: 'get',
                    url: API_PATH + '/customer/findAllAndWx',
                    dataType: 'json',
                }).then(
                    res => {
                        if(res.data.code == 0){
                            let weChatPublics = [];
                            res.data.data.forEach(
                                item => {
                                    weChatPublics = weChatPublics.concat(item.weChatPublics);
                                }
                            );
                            this.$set(this.merchant[0], 'weChatPublics', weChatPublics);
                            this.merchant = this.merchant.concat(res.data.data);
                            this.accountList = this.accountList.concat(weChatPublics)
                        }
                    },
                );
            },
        },
        components:{
            SelectGroup,
        }
    }
</script>

<style>
    .com-merchant-select{display: inline-block;vertical-align: top;}
</style>
